/**
 
 * 
 */
package nl.boektrust.btsoep.server;

import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueFactory;

/**
 * @author rao3
 *
 * the implementation of the server that can serve XML requests to Koppelvlak bookstores. 
 */
public class ImportImageFile extends HttpServlet {
	private boolean isObjectifyServiceRegistered = false;
	private ServletContext context;

	
	ServletContext getContext() {
		return this.context;
	}

	public void init() throws ServletException {
		context = getServletContext();
		//System.err.println("Real Path = " + context.getRealPath("/"));
	}

	/**
	 * 
	 */
	public ImportImageFile() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param delegate
	 */
	public ImportImageFile(Object delegate) {
		//super(delegate);
		// TODO Auto-generated constructor stub
	}
	
	
	public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ServletException, IOException  
	{
		
		/*
		 * get raw XML from the inputstream. 
		 */
		
		String urlString = request.getParameter("urlString");
		String recordReference = request.getParameter("recordReference");
		String imageType = request.getParameter("imageType");
		Queue queue = QueueFactory.getQueue("images");
		queue.add(withUrl("/importimagefiletask").param("urlString", urlString).param("recordReference",recordReference).param("imageType", imageType));
		response.setContentType("text/plain");
		response.getOutputStream().print("Added image update at URL "+urlString+" to task queue"+"images");
		response.getOutputStream().close();
	} 
	
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		doPost(request, response);
	}


}
